﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NetMicro.HttpClient.AspectExtend;
using NetMicro.HttpClient.Polly;

namespace NetMicro.HttpClient.Extensions
{
    /// <summary>
    /// 远程请求服务拓展类
    /// </summary>

    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// 注册远程请求
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static IServiceCollection AddHttpClientExtend(this IServiceCollection services, Action<IServiceCollection> configure = null)
        {
            // 注册远程请求代理接口
            services.AddHttpProxy();
            services.AddHttpClient();
            services.AddTransient<PolicyHandler>();
            services.AddHttpClient("DefaltHttpClientWithPolly")
                .AddHttpMessageHandler<PolicyHandler>();
            // 注册其他客户端
            configure?.Invoke(services);

            return services;
        }
    }
}
